package com.yanyeori.framework.web.config;

import com.yanyeori.framework.web.advice.GlobalExceptionAdvice;
import com.yanyeori.framework.web.configprop.WebConfigProps;
import com.yanyeori.framework.web.filter.WebRequestFilter;
import com.yanyeori.framework.web.http.accept.HttpHeaderContextHandler;
import com.yanyeori.framework.web.http.request.feign.FeignRequestConfig;
import com.yanyeori.framework.web.http.request.okhttp.OkHttpRequestConfig;
import com.yanyeori.framework.web.http.request.resttemplate.RestClientHttpRequestConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * web模块自动配置
 *
 * @author chenkuan 2021/7/20
 */
@Configuration
@EnableConfigurationProperties({WebConfigProps.class})
@Import({GlobalExceptionAdvice.class, RestClientHttpRequestConfig.class, FeignRequestConfig.class, OkHttpRequestConfig.class})
public class WebAutoConfig {

    @Bean
    public WebRequestFilter webRequestFilter() {
        return new WebRequestFilter();
    }

    @Bean
    @ConditionalOnMissingBean(HttpHeaderContextHandler.class)
    public HttpHeaderContextHandler httpHeaderContextHandler() {
        return new HttpHeaderContextHandler();
    }
}
